﻿//********************************************************************************//
//创建日期：<创建日期，2016-11-03>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：全年表信息查询
//********************************************************************************//
using BLL;
using BLL.Access;
using DevExpress.Web;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using System.Text.RegularExpressions;


namespace Web.Pages.QuShui.DiXiaS.ChaXunGL
{
    public partial class QuanNianBXXCX : BasePage
    {
        #region 属性
        private int wtype
        {
            get
            {
                return Convert.ToInt32(ViewState["wtype"]);
            }
            set
            {
                ViewState["wtype"] = value;
            }
        }
        /// <summary>
        /// 保存结果集1
        /// </summary>
        private DataTable dtShuiBiaoXX
        {
            get
            {
                return ViewState["dtShuiBiaoXX"] as DataTable;
            }
            set
            {
                ViewState["dtShuiBiaoXX"] = value;
            }
        }
        /// <summary>
        /// 保存结果集2
        /// </summary>
        private DataTable dtGridData
        {
            get
            {
                return ViewState["dtGridData"] as DataTable;
            }
            set
            {
                ViewState["dtGridData"] = value;
            }
        }

        /// <summary>
        /// 保存结果集3
        /// </summary>
        private DataTable dtGridData2_2
        {
            get
            {
                return ViewState["dtGridData3"] as DataTable;
            }
            set
            {
                ViewState["dtGridData3"] = value;
            }
        }
        /// <summary>
        /// 保存结果集4
        /// </summary>
        private DataTable dtGridData4
        {
            get
            {
                return ViewState["dtGridData4"] as DataTable;
            }
            set
            {
                ViewState["dtGridData4"] = value;
            }
        }
        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();
        

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
            }
            this.gvShuiBiaoXX.DataSource = this.dtShuiBiaoXX;
            this.gvShuiBiaoXX.DataBind();

            gvGridTab2.DataSource = dtGridData;
            gvGridTab2.DataBind();

            gvGridTab3.DataSource = dtGridData;
            gvGridTab3.DataBind();


        }

        /// <summary>
        /// 查询信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnChaXun_Click(object sender, EventArgs e)
        {
            if (cmbSLY.Text != "" && cmbSLM.Text!="")
            {
                LoadGridDataTab1();
                if (this.dtShuiBiaoXX == null || this.dtShuiBiaoXX.Rows.Count < 1)
                {
                    txtYongHuH2.Text = "";
                    txtYongHuM2.Text = "";
                    txtHuanNeiHW.Text = "";
                    txJingBianH.Text = "";
                    txtDiZhi.Text = "";
                    txtXingZhengQ.Text = "";
                    txShuiJia.Text = "";
                    txtQuShuiDZ2.Text = "";
                    txtShuiBiaoBH2.Text = "";
                    txtShuiLiangLB.Text = "";
                    txtCeHao.Text = "";
                    txtBiaoBiaoJ.Text = "";
                    txtBiaoFenL.Text = "";
                    txtZongBiaoH.Text = "";
                    memoBeiZhu.Text = "";
                    zjl.Text = "共0条";
                }
            }
        }

        protected void btnChaXuntab2_Click(object sender, EventArgs e)
        {
            if (cmbYtab2.Text != "")
            {
                LoadGridDataTab(2);
            }
        }
        protected void btnChaXuntab3_Click(object sender, EventArgs e)
        {
            if (cmbYtab3.Text != "")
            {
                LoadGridDataTab(3);
            }
        }
        protected void btnChaXuntab4_Click(object sender, EventArgs e)
        {
            if (cmbYtab4.Text != "")
            {
                LoadGridDataTab(4);
            }
        }

        /// <summary>
        /// tab1导出excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExportExcel_Click(object sender, EventArgs e)
        {
            if (this.dtShuiBiaoXX == null || this.dtShuiBiaoXX.Rows.Count < 1)
            {
                PageTools.AlertMsg(this, "没有符合的数据导出");
            }
            else
            {
                PageTools.ExportExcel(this.dtShuiBiaoXX);
            }
        }


        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            this.wtype = BusinessTool.WType;
            gvShuiBiaoXX.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            //水量年月
            int water_y_m = BusinessTool.GetSLYMorZWNY(1, wtype);
            
            for (int i = (water_y_m / 100) - 10; i <= (water_y_m / 100); i++)
            {
                cmbSLY.Items.Add(i.ToString(), i);
                cmbYtab2.Items.Add(i.ToString(),i);
                cmbYtab3.Items.Add(i.ToString(), i);
                cmbYtab4.Items.Add(i.ToString(), i);
            }
            cmbSLY.SelectedIndex = 10;
            cmbYtab2.SelectedIndex = 10;
            cmbYtab3.SelectedIndex = 10;
            cmbYtab4.SelectedIndex = 10;

            for (int i = 1; i < 13; i++)
            {
                cmbSLM.Items.Add(i.ToString(), i);
                cmbMtab3.Items.Add(i.ToString(),i);
                cmbMtab4.Items.Add(i.ToString(),i);
            }
            //cmbMtab3.Items.Add("全年", 0);
            cmbSLM.Value = water_y_m % 100;
            cmbMtab4.Items.Add("全年", 0);
            cmbMtab3.Value = water_y_m % 100;
            cmbMtab4.Value = water_y_m % 100;
            PageTools.QSLoadCombox(cmbXingZhengQ, PageTools.eLoadType.行政区QS, null, "");
            PageTools.QSLoadCombox(cmbZGBM, PageTools.eLoadType.管理部门QS, null, "");
            if (wtype == 2)
            {
                jbh.InnerText = "井编号：";
                rabJingBianH.Text = "井编号";
                PageTools.QSLoadCombox(cmbJinglx, PageTools.eLoadType.井类型QS, null, "");
                PageTools.QSLoadCombox(cmbJingXZ, PageTools.eLoadType.井性质QS, null, "");
                PageTools.QSLoadCombox(cmbJingBJ, PageTools.eLoadType.井标记QS, null, "");
            }
            else if (wtype == 1)
            {
                jbh.InnerText = "取水口编号：";
                rabJingBianH.Text = "取水口编号";
                dxs.Visible = false;
                chkShenJingSF.ClientVisible = false;
                cmbShenJingSF.ClientVisible = false;
                txtShenJingSF.ClientVisible = false;
            }
            
            PageTools.QSLoadCombox(cmbQuShuiYT, PageTools.eLoadType.取水用途QS, null, "");
            PageTools.QSLoadCombox(cmbHangYeFL, PageTools.eLoadType.行业分类QS, null, "");
            PageTools.QSLoadCombox(cmbLiuYu, PageTools.eLoadType.流域QS, null, "");
            PageTools.QSLoadCombox(cmbShuiZiYFQ, PageTools.eLoadType.水资源分区QS, null, "");
            PageTools.QSLoadCombox(cmbShuiLiFP, PageTools.eLoadType.水利分片QS, null, "");
            PageTools.QSLoadCombox(cmbShuiLiangLB, PageTools.eLoadType.水量类别QS, null, "");

            PageTools.QSLoadCombox(cmbSL1tab2, PageTools.eLoadType.水量类别QS, null, "");
            PageTools.QSLoadCombox(cmbSL1tab3, PageTools.eLoadType.水量类别QS, null, "");
            PageTools.QSLoadCombox(cmbSL1tab4, PageTools.eLoadType.水量类别QS, null, "");
            cmbSL1tab3.Items.Add("开采量", "6"); cmbSL1tab3.Items.Add("回灌量", "7"); cmbSL1tab3.Items.Add("总水量", "8");
            cmbSL1tab4.Items.Add("开采量", "6"); cmbSL1tab4.Items.Add("回灌量", "7"); cmbSL1tab4.Items.Add("总水量", "8");
            cmbSL1tab2.Items.Add("开采量", "6"); cmbSL1tab2.Items.Add("回灌量", "7"); cmbSL1tab2.Items.Add("总水量", "8");
        }
        /// <summary>
        /// 加载水表信息
        /// </summary>
        private void LoadGridDataTab1()
        {
            int wtype = BusinessTool.WType;
            if (cmbSLY.Text.Trim() != "" && cmbSLM.Text.Trim() != "")
            {
                int ym = Convert.ToInt32(cmbSLY.Text) * 100 + Convert.ToInt32(cmbSLM.Text);
                int hnhw = cmbHuanNeiHW.Value != null ? Convert.ToInt32(cmbHuanNeiHW.Value) : 0;
                string xzq = cmbXingZhengQ.Text != "" ? cmbXingZhengQ.Value.ToString() : null;
                string zgbm = cmbZGBM.Text != "" ? cmbZGBM.Value.ToString() : null;
                string jlx = null;
                string jxz = null;
                string jbz = null;
                if (wtype == 2)
                {
                    jlx = cmbJinglx.Text != "" ? cmbJinglx.Value.ToString() : null;
                    jxz = cmbJingXZ.Text != "" ? cmbJingXZ.Value.ToString() : null;
                    jbz = cmbJingBJ.Text != "" ? cmbJingBJ.Value.ToString() : null;
                }

                string yhh = chkYongHuH.Checked && txtYongHuH.Text != "" ? txtYongHuH.Text : null;
                string jbh = rabJingBianH.Checked && txtJingBianH.Text != "" ? txtJingBianH.Text : null;
                string sbbh = rabShuiBiaoBH.Checked && txtShuiBiaoBH.Text != "" ? txtShuiBiaoBH.Text : null;
                string yhm = chkYongHuM.Checked && txtYongHuM.Text != "" ? txtYongHuM.Text : null;
                string xkz = chkYongHuDZ.Checked && txtYongHuDZ.Text != "" ? txtYongHuDZ.Text : null;
                string qsdz = rabQuShuiDZ.Checked && txtQuShuiDZ.Text != "" ? txtQuShuiDZ.Text : null;
                string qsyt = chkQuShuiYT.Checked && cmbQuShuiYT.Text != "" ? cmbQuShuiYT.Value.ToString() : null;
                string hyfl = chkHangYeFL.Checked && cmbHangYeFL.Text != "" ? cmbHangYeFL.Value.ToString() : null;
                string ly = chkLiuYu.Checked && cmbLiuYu.Text != "" ? cmbLiuYu.Value.ToString() : null;
                string szyfq = chkShuiZiYFQ.Checked && cmbShuiZiYFQ.Text != "" ? cmbShuiZiYFQ.Value.ToString() : null;
                string slfp = chkShuiLiFP.Checked && cmbShuiLiFP.Text != "" ? cmbShuiLiFP.Value.ToString() : null;
                string sllb = chkShuiLiangLB.Checked && cmbShuiLiangLB.Text != "" ? cmbShuiLiangLB.Value.ToString() : null;
                string ch = chkCeHao.Checked && txtCeHao2.Text != "" ? txtCeHao2.Text : null;
                string sj = chkShuiJia.Checked && cmbShuiJia.Text != "" && txtShuiJia.Text != "" ? cmbShuiJia.Text + txtShuiJia.Text : null;
                string sjsf = chkShenJingSF.Checked && cmbShenJingSF.Text != "" && txtShenJingSF.Text != "" ? cmbShenJingSF.Text + txtShenJingSF.Text : null;

                this.dtShuiBiaoXX = _SpHelper.P_QSCX_SHUIBIAOXXCX_QN(wtype, ym, hnhw, xzq, zgbm, jlx, jxz,
                    jbz, yhh, jbh, sbbh, yhm, xkz, qsdz, qsyt, hyfl, ly, szyfq, slfp, sllb, ch, sj, sjsf, 0).Tables[0];

                if (wtype == 1)
                {
                    gvShuiBiaoXX.Columns.Clear();
                    LoadColumnDate(gvShuiBiaoXX, "S_SHUIBIAOBH", "水表号", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_QUSHUIK", "取水口号", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_YONGHUH", "用户号", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_XUKEZBH", "许可证", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_YONGHUM", "用户名", 200);
                    LoadColumnDate(gvShuiBiaoXX, "S_JINGDIZ", "取水地点", 200);
                    LoadColumnDate(gvShuiBiaoXX, "S_QUSHUIMC", "取水用途", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_FENLEIMC", "行业分类", 200);
                    LoadColumnDate(gvShuiBiaoXX, "S_XINGZHENGQBH", "行政区号", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_XINGZHENGQM", "行政区名", 80);
                    LoadColumnDate(gvShuiBiaoXX, "HNHW", "环内环外", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_LIUYUMC", "流域", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_SHUIZIYMC", "水资源分区", 120);
                    LoadColumnDate(gvShuiBiaoXX, "S_SHUILIFPMC", "水利分片", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_YEWUY", "业务员", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_YEWUY1", "业务员号", 80);
                    //LoadColumnDate(gvShuiBiaoXX, "", "水资源分区号", 80);
                    //LoadColumnDate(gvShuiBiaoXX, "", "水利分片号", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_BEIZHU", "备注", 80);
                    LoadColumnDate(gvShuiBiaoXX, "D_TIANJIARQ", "创建日期", 80, "yyyy-MM-dd");
                    LoadColumnDate(gvShuiBiaoXX, "D_CAOZUORQ", "修改日期", 80, "yyyy-MM-dd");
                    LoadColumnDate(gvShuiBiaoXX, "S_KAISHINY", "增表日期", 80);
                    LoadColumnDate(gvShuiBiaoXX, "", "销表日期", 80);
                    LoadColumnDate(gvShuiBiaoXX, "N_SHUIJIA", "水价", 80, "0.00");
                    LoadColumnDate(gvShuiBiaoXX, "S_QUSHUIKM", "取水口名", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_BIAOFENL", "表分类", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_BIAOHAO", "总表号", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_FEETYPE", "收费标准", 80);
                }
                else if (wtype == 2)
                {
                    gvShuiBiaoXX.Columns.Clear();
                    LoadColumnDate(gvShuiBiaoXX, "S_SHUIBIAOBH", "水表编号", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_QUSHUIK", "井编号", 60);
                    LoadColumnDate(gvShuiBiaoXX, "S_YONGHUH", "用户号", 60);
                    LoadColumnDate(gvShuiBiaoXX, "S_XUKEZHENGBH", "许可证", 60);
                    LoadColumnDate(gvShuiBiaoXX, "S_YONGHUM", "用户名", 200);
                    LoadColumnDate(gvShuiBiaoXX, "S_JINGDIZ", "取水地址", 200);
                    LoadColumnDate(gvShuiBiaoXX, "S_SHUILIANGLB", "水量类别", 70);
                    LoadColumnDate(gvShuiBiaoXX, "S_CEHAO", "册号", 60);
                    LoadColumnDate(gvShuiBiaoXX, "S_QUSHUIMC", "取水用途", 70);
                    LoadColumnDate(gvShuiBiaoXX, "S_FENLEIMC", "行业分类", 120);
                    LoadColumnDate(gvShuiBiaoXX, "S_XINGZHENGQM", "行政区名", 60);
                    LoadColumnDate(gvShuiBiaoXX, "HNHW", "环线内外", 60);
                    LoadColumnDate(gvShuiBiaoXX, "S_LIUYUMC", "流域", 60);
                    LoadColumnDate(gvShuiBiaoXX, "S_SHUIZIYMC", "水资源分区", 100);
                    LoadColumnDate(gvShuiBiaoXX, "S_SHUILIFPMC", "水利分片", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_BUMENBH", "主管部门号", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_BUMENMC", "主管部门名", 80);
                    LoadColumnDate(gvShuiBiaoXX, "S_YEWUY", "业务员", 60);
                    LoadColumnDate(gvShuiBiaoXX, "S_BEIZHU", "备注", 100);
                    LoadColumnDate(gvShuiBiaoXX, "D_TIANJIARQ", "创建日期", 85, "yyyy-MM-dd");
                    LoadColumnDate(gvShuiBiaoXX, "D_CAOZUORQ", "修改日期", 85, "yyyy-MM-dd");
                    LoadColumnDate(gvShuiBiaoXX, "D_TIANJIARQ", "增表日期", 85, "yyyy-MM-dd");
                    LoadColumnDate(gvShuiBiaoXX, "", "销表日期", 85, "yyyy-MM-dd");
                    LoadColumnDate(gvShuiBiaoXX, "N_SHUIJIA", "水价", 60, "0.00");
                    LoadColumnDate(gvShuiBiaoXX, "JLX", "井类型", 70);
                    LoadColumnDate(gvShuiBiaoXX, "JXZ", "井性质", 70);
                    LoadColumnDate(gvShuiBiaoXX, "S_YUZHIMC", "井标记", 70);
                    LoadColumnDate(gvShuiBiaoXX, "S_LAOBIANH", "原井号", 60);
                    LoadColumnDate(gvShuiBiaoXX, "S_BIAOFENL", "表分类", 60);
                    LoadColumnDate(gvShuiBiaoXX, "S_BIAOBIAOJ", "表标记", 60);
                    LoadColumnDate(gvShuiBiaoXX, "S_ZONGBIAOH", "总表号", 60);
                }
                gvShuiBiaoXX.DataSource = this.dtShuiBiaoXX;
                gvShuiBiaoXX.DataBind();
                if (this.dtShuiBiaoXX != null && this.dtShuiBiaoXX.Rows.Count > 0)
                {
                    zjl.Text = "共" + this.dtShuiBiaoXX.Rows.Count.ToString() + "条";
                    gvShuiBiaoXX.FocusedRowIndex = -1;
                    gvShuiBiaoXX.FocusedRowIndex = 0;
                    //SetData();
                }
            }
        }
        /// <summary>
        /// 加载水表全年用水情况
        /// </summary>
        private void LoadGridDataTab(int index)
        {//Pr_QueryWaterMeterAllYear
            //Pr_QueryWaterMeterAllYearBelow
            int wtype = BusinessTool.WType;
            int Y = 0, M = 0;
            //int ym = BusinessTool.GetSLYMorZWNY(1, wtype);
            int hzlx = cmbHZLBtab4.Text != "" ? Convert.ToInt32(cmbHZLBtab4.Value) : 0;
            if (index == 2)
            {
                Y = Convert.ToInt32(cmbYtab2.Value);
                M = 0;
            }
            else if (index == 3)
            {
                Y = Convert.ToInt32(cmbYtab3.Value);
                M = Convert.ToInt32(cmbMtab3.Value);
            }
            else if (index == 4)
            {
                Y = Convert.ToInt32(cmbYtab4.Value);
                M = Convert.ToInt32(cmbMtab4.Value);
            }
            
            string strSL = null;
            string sl1 =""; 
            string sl2 = "";
            string sl3 = "";
            int val = 0;
            if (index == 2)
            {
                sl1 = cmbSL1tab2.Text;
                sl2 = cmbSL2tab2.Text;
                sl3 = txtSLtab2.Text;
                val = Convert.ToInt32(cmbSL1tab2.Value);
            }
            else if (index == 3)
            {
                sl1 = cmbSL1tab3.Text;
                sl2 = cmbSL2tab3.Text;
                sl3 = txtSLtab3.Text;
                val = Convert.ToInt32(cmbSL1tab3.Value);
            }
            else if (index == 4)
            {
                sl1 = cmbSL1tab4.Text;
                sl2 = cmbSL2tab4.Text;
                sl3 = txtSLtab4.Text;
                val = Convert.ToInt32(cmbSL1tab4.Value);
            }
            //水量条件
            if (sl1 != "" && sl2 != "" && sl3 != "")
            {
                if (val == 1)
                {
                    strSL += " AND I_PTC" + sl2 + sl3;
                }
                else if (val == 2)
                {
                    strSL += " AND I_CGC" + sl2 + sl3;
                }
                else if (val == 3)
                {
                    strSL += " AND I_CGG" + sl2 + sl3;
                }
                else if (val == 4)
                {
                    strSL += " AND I_KQC" + sl2 + sl3;
                }
                else if (val == 5)
                {
                    strSL += " AND I_ZG" + sl2 + sl3;
                }
                else if (val == 6)
                {
                    strSL += " AND I_KCL" + sl2 + sl3;
                }
                else if (val == 7)
                {
                    strSL += " AND I_HGL" + sl2 + sl3;
                }
                else if (val == 8)
                {
                    strSL += " AND I_ZSL" + sl2 + sl3;
                }
            }
            string yhh = chkYongHuH.Checked && txtYongHuH.Text != "" ? txtYongHuH.Text : null;
            string jbh = rabJingBianH.Checked && txtJingBianH.Text != "" ? txtJingBianH.Text : null;
            string sbbh = rabShuiBiaoBH.Checked && txtShuiBiaoBH.Text != "" ? txtShuiBiaoBH.Text : null;
            string yhm = chkYongHuM.Checked && txtYongHuM.Text != "" ? txtYongHuM.Text : null;
            string xkz = chkYongHuDZ.Checked && txtYongHuDZ.Text != "" ? txtYongHuDZ.Text : null;
            string qsdz = rabQuShuiDZ.Checked && txtQuShuiDZ.Text != "" ? txtQuShuiDZ.Text : null;
            string qsyt = chkQuShuiYT.Checked && cmbQuShuiYT.Text != "" ? cmbQuShuiYT.Value.ToString() : null;
            string hyfl = chkHangYeFL.Checked && cmbHangYeFL.Text != "" ? cmbHangYeFL.Value.ToString() : null;
            string ly = chkLiuYu.Checked && cmbLiuYu.Text != "" ? cmbLiuYu.Value.ToString() : null;
            string szyfq = chkShuiZiYFQ.Checked && cmbShuiZiYFQ.Text != "" ? cmbShuiZiYFQ.Value.ToString() : null;
            string slfp = chkShuiLiFP.Checked && cmbShuiLiFP.Text != "" ? cmbShuiLiFP.Value.ToString() : null;
            string sllb = chkShuiLiangLB.Checked && cmbShuiLiangLB.Text != "" ? cmbShuiLiangLB.Value.ToString() : null;
            string ch = chkCeHao.Checked && txtCeHao2.Text != "" ? txtCeHao2.Text : null;
            string sj = chkShuiJia.Checked && cmbShuiJia.Text != "" && txtShuiJia.Text != "" ? cmbShuiJia.Text + txtShuiJia.Text : null;
            string sjsf = chkShenJingSF.Checked && cmbShenJingSF.Text != "" && txtShenJingSF.Text != "" ? cmbShenJingSF.Text + txtShenJingSF.Text : null;
            
            if (index==2)
            {
                dtGridData = SearchSpHelper.P_QSCX_SBQNYSQK(wtype, Y,M,
                yhh, jbh, sbbh, yhm, xkz, qsdz, qsyt, hyfl, ly, szyfq, slfp, sllb, ch, sj, sjsf, strSL, 0).Tables[0];
                if (wtype == 2)
                {
                    gvGridTab2.Columns.Clear();
                    LoadColumnDate(gvGridTab2, "S_SHUIBIAOBH", "水表号", 80);
                    LoadColumnDate(gvGridTab2, "S_JINGBH", "井编号", 80);
                    LoadColumnDate(gvGridTab2, "S_YONGHUH", "用户号", 80);
                    LoadColumnDate(gvGridTab2, "S_YONGHUM", "用户名", 200);
                    LoadColumnDate(gvGridTab2, "S_XUKEZ", "许可证号", 80);
                    LoadColumnDate(gvGridTab2, "S_JINGLX", "井类型", 80);
                    LoadColumnDate(gvGridTab2, "I_PTC", "普通采", 80);
                    LoadColumnDate(gvGridTab2, "I_KQC", "矿泉采", 80);
                    LoadColumnDate(gvGridTab2, "I_CGC", "采灌采", 80);
                    LoadColumnDate(gvGridTab2, "I_CGG", "采灌灌", 80);
                    LoadColumnDate(gvGridTab2, "I_ZG", "专灌", 80);
                    LoadColumnDate(gvGridTab2, "I_KCL", "开采量", 80);
                    LoadColumnDate(gvGridTab2, "I_HGL", "回灌量", 80);
                    LoadColumnDate(gvGridTab2, "I_ZSL", "总水量", 80);
                    LoadColumnDate(gvGridTab2, "N_SHENJINGSF", "深井水费", 110, "0.00");
                }
                else if (wtype == 1)
                {
                    gvGridTab2.Columns.Clear();
                    LoadColumnDate(gvGridTab2, "S_SHUIBIAOBH", "水表号", 80);
                    LoadColumnDate(gvGridTab2, "S_JINGBH", "取水口编号", 80);
                    LoadColumnDate(gvGridTab2, "S_QUSHUIDZ", "取水口地址", 180);
                    LoadColumnDate(gvGridTab2, "S_YONGHUH", "用户号", 80);
                    LoadColumnDate(gvGridTab2, "S_YONGHUM", "用户名", 200);
                    LoadColumnDate(gvGridTab2, "S_XUKEZ", "许可证号", 80);
                    LoadColumnDate(gvGridTab2, "I_QSL", "取水量", 110);
                    LoadColumnDate(gvGridTab2, "I_KZSL", "开账水量", 110);
                    LoadColumnDate(gvGridTab2, "N_KZJE", "开账金额", 110, "0.00");
                    LoadColumnDate(gvGridTab2, "I_DL", "发电量", 90);
                    LoadColumnDate(gvGridTab2, "N_KZDL", "开账电量", 80);
                    LoadColumnDate(gvGridTab2, "S_SHOUFEILX", "收费标准", 80);
                }
                gvGridTab2.DataSource = dtGridData;
                gvGridTab2.DataBind();
                if (this.dtGridData != null && this.dtGridData.Rows.Count > 0)
                {
                    zjltab2.Text = "共" + (this.dtGridData.Rows.Count - 1) + "条";
                    gvGridTab2.FocusedRowIndex = -1;
                    gvGridTab2.FocusedRowIndex = 0;
                }
            }
            else if(index==3)
            {
                dtGridData = SearchSpHelper.P_QSCX_SBQNYSQK(wtype, Y,M,
                yhh, jbh, sbbh, yhm, xkz, qsdz, qsyt, hyfl, ly, szyfq, slfp, sllb, ch, sj, sjsf, strSL, 0).Tables[0];
                if (wtype == 2)
                {
                    gvGridTab3.Columns.Clear();
                    LoadColumnDate(gvGridTab3, "S_SHUIBIAOBH", "水表号", 80);
                    LoadColumnDate(gvGridTab3, "S_JINGBH", "井编号", 80);
                    LoadColumnDate(gvGridTab3, "S_YONGHUH", "用户号", 80);
                    LoadColumnDate(gvGridTab3, "S_YONGHUM", "用户名", 200);
                    LoadColumnDate(gvGridTab3, "S_XUKEZ", "许可证号", 80);
                    LoadColumnDate(gvGridTab3, "S_JINGLX", "井类型", 80);
                    LoadColumnDate(gvGridTab3, "I_PTC", "普通采", 80);
                    LoadColumnDate(gvGridTab3, "I_KQC", "矿泉采", 80);
                    LoadColumnDate(gvGridTab3, "I_CGC", "采灌采", 80);
                    LoadColumnDate(gvGridTab3, "I_CGG", "采灌灌", 80);
                    LoadColumnDate(gvGridTab3, "I_ZG", "专灌", 80);
                    LoadColumnDate(gvGridTab3, "I_KCL", "开采量", 80);
                    LoadColumnDate(gvGridTab3, "I_HGL", "回灌量", 80);
                    LoadColumnDate(gvGridTab3, "I_ZSL", "总水量", 80);
                    LoadColumnDate(gvGridTab3, "N_SHENJINGSF", "深井水费", 90, "0.00");
                }
                else if (wtype == 1)
                {
                    gvGridTab3.Columns.Clear();
                    LoadColumnDate(gvGridTab3, "S_SHUIBIAOBH", "水表号", 80);
                    LoadColumnDate(gvGridTab3, "S_JINGBH", "取水口编号", 80);
                    LoadColumnDate(gvGridTab3, "S_QUSHUIDZ", "取水口地址", 180);
                    LoadColumnDate(gvGridTab3, "S_YONGHUH", "用户号", 80);
                    LoadColumnDate(gvGridTab3, "S_YONGHUM", "用户名", 200);
                    LoadColumnDate(gvGridTab3, "S_XUKEZ", "许可证号", 80);
                    LoadColumnDate(gvGridTab3, "I_QSL", "取水量", 110);
                    LoadColumnDate(gvGridTab3, "I_KZSL", "开账水量", 110);
                    LoadColumnDate(gvGridTab3, "N_KZJE", "开账金额", 110, "0.00");
                    LoadColumnDate(gvGridTab3, "I_DL", "发电量", 90);
                    LoadColumnDate(gvGridTab3, "N_KZDL", "开账电量", 80);
                    LoadColumnDate(gvGridTab3, "S_SHOUFEILX", "收费标准", 80);
                }
                gvGridTab3.DataSource = dtGridData;
                gvGridTab3.DataBind();
                if (this.dtGridData != null && this.dtGridData.Rows.Count > 0)
                {
                    zjltab3.Text = "共" + (this.dtGridData.Rows.Count-1) + "条";
                    gvGridTab3.FocusedRowIndex = -1;
                    gvGridTab3.FocusedRowIndex = 0;
                }
            }
            else if (index==4)
            {
                dtGridData = SearchSpHelper.P_QSCX_SBYYSHZ(wtype, hzlx,Y,M,
                yhh, jbh, sbbh, yhm, xkz, qsdz, qsyt, hyfl, ly, szyfq, slfp, sllb, ch, sj, sjsf, strSL).Tables[0];
                if (wtype == 1) 
                {
                    gvGridTab4.Columns.Clear();
                    LoadColumnDate(gvGridTab4, "S_HUIZONGMC", "名称", 80);
                    LoadColumnDate(gvGridTab4, "I_BIAOSHU", "表数", 80);
                    LoadColumnDate(gvGridTab4, "I_QSL", "取水量", 110);
                    LoadColumnDate(gvGridTab4, "I_KZSL", "开帐水量", 110);
                    LoadColumnDate(gvGridTab4, "N_KZJE", "开账金额", 110, "0.00");
                    LoadColumnDate(gvGridTab4, "I_DL", "发电量", 110);
                    LoadColumnDate(gvGridTab4, "N_KZDL", "开账电量", 110);
                }
                else
                {
                    gvGridTab4.Columns.Clear();
                    LoadColumnDate(gvGridTab4, "S_HUIZONGMC", "名称", 80);
                    LoadColumnDate(gvGridTab4, "I_BIAOSHU", "表数", 80);
                    LoadColumnDate(gvGridTab4, "I_PTC", "普通采", 80);
                    LoadColumnDate(gvGridTab4, "I_KQC", "矿泉采", 80);
                    LoadColumnDate(gvGridTab4, "I_CGC", "采灌采", 80);
                    LoadColumnDate(gvGridTab4, "I_CGG", "采灌灌", 80);
                    LoadColumnDate(gvGridTab4, "I_ZG", "专灌", 80);
                    LoadColumnDate(gvGridTab4, "I_KCL", "开采量", 80);
                    LoadColumnDate(gvGridTab4, "I_HGL", "回灌量", 80);
                    LoadColumnDate(gvGridTab4, "I_ZSL", "总水量", 80);
                    LoadColumnDate(gvGridTab4, "N_SHENJINGSF", "", 80,"0.00");
                    LoadColumnDate(gvGridTab4, "N_SHUIZIYSF", "", 80, "0.00");
                }
                gvGridTab4.DataSource = dtGridData;
                gvGridTab4.DataBind();
                if (this.dtGridData != null && this.dtGridData.Rows.Count > 0)
                {
                    zjltab4.Text = "共" + (this.dtGridData.Rows.Count-1) + "条";
                    gvGridTab4.FocusedRowIndex = -1;
                    gvGridTab4.FocusedRowIndex = 0;
                }
            }
            
        }
        
        
       

        /// <summary>
        /// 前台表格行改变事件回调方法
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "setinfo")
            {
                string msg = "";
                if (this.dtShuiBiaoXX != null)
                {
                    DataTable dt_temp = _SpHelper.P_QSCX_SHUIBIAOXXCX_QN(BusinessTool.WType, null, 0, null, null, null, null,
                null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, id).Tables[0];

                    msg = string.Join("|",
                        dt_temp.Rows[0]["S_YONGHUH"].ToString(),
                        dt_temp.Rows[0]["S_YONGHUM"].ToString(),
                         dt_temp.Rows[0]["HNHW"].ToString(),
                        dt_temp.Rows[0]["S_QUSHUIK"].ToString(),
                        dt_temp.Rows[0]["S_DIZHI"].ToString(),
                         dt_temp.Rows[0]["S_XINGZHENGQM"].ToString(),
                        dt_temp.Rows[0]["N_SHUIJIA"].ToString(),
                         dt_temp.Rows[0]["S_JINGDIZ"].ToString(),
                          dt_temp.Rows[0]["S_SHUIBIAOBH"].ToString(),
                          dt_temp.Rows[0]["S_SHUILIANGLB"].ToString(),
                        dt_temp.Rows[0]["S_CEHAO"].ToString(),
                         dt_temp.Rows[0]["S_BIAOBIAOJ"].ToString(),
                        dt_temp.Rows[0]["S_BIAOFENL"].ToString(),
                         dt_temp.Rows[0]["S_ZONGBIAOH"].ToString(),
                        dt_temp.Rows[0]["S_BEIZHU"].ToString()
                        );
                }

                e.Result = e.Parameter + "|0|" + msg;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvGrid2Tab2_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            string sbh = this.hdCollection.Get("SBH").ToString();
            int year = Convert.ToInt32(cmbYtab2.Text);
            DataTable dt = SearchSpHelper.P_QSCX_SBQNYSQK2(this.wtype, year, sbh).Tables[0];

            if (this.wtype == 2)
            {
                gvGrid2Tab2.Columns.Clear();
                LoadColumnDate(gvGrid2Tab2, "I_M2", "月份", 80);
                LoadColumnDate(gvGrid2Tab2, "I_PTC", "普通采", 80);
                LoadColumnDate(gvGrid2Tab2, "I_KQC", "矿泉采", 80);
                LoadColumnDate(gvGrid2Tab2, "I_CGC", "采灌采", 80);
                LoadColumnDate(gvGrid2Tab2, "I_KCL", "开采量", 80);
                LoadColumnDate(gvGrid2Tab2, "I_CGG", "采灌灌", 80);
                LoadColumnDate(gvGrid2Tab2, "I_ZG", "专灌", 80);
                LoadColumnDate(gvGrid2Tab2, "I_HGL", "回灌量", 80);
                LoadColumnDate(gvGrid2Tab2, "I_ZSL", "总水量", 80);
                LoadColumnDate(gvGrid2Tab2, "N_SJSF", "深井水费", 90, "0.00");
            }
            else if (this.wtype == 1)
            {
                gvGrid2Tab2.Columns.Clear();
                LoadColumnDate(gvGrid2Tab2, "I_M2", "月份", 80);
                LoadColumnDate(gvGrid2Tab2, "I_QSL", "取水量", 80);
                LoadColumnDate(gvGrid2Tab2, "I_KZSL", "开账水量", 80);
                LoadColumnDate(gvGrid2Tab2, "N_KZJE", "开账金额", 80, "0.00");
                LoadColumnDate(gvGrid2Tab2, "I_DL", "发电量", 80);
                LoadColumnDate(gvGrid2Tab2, "N_KZDL", "开账电量", 80);
            }
            gvGrid2Tab2.DataSource = dt;
            gvGrid2Tab2.DataBind();
        }


        private void LoadColumnDate(ASPxGridView gv, string fieldName, string caption, int width)
        {
            GridViewDataTextColumn c = new GridViewDataTextColumn();
            c.FieldName = fieldName;
            c.Caption = caption;
            c.Width = width;
            gv.Columns.Add(c);
        }

        private void LoadColumnDate(ASPxGridView gv, string fieldName, string caption, int width, string format)
        {
            GridViewDataTextColumn c = new GridViewDataTextColumn();
            c.FieldName = fieldName;
            c.Caption = caption;
            c.Width = width;
            c.PropertiesEdit.DisplayFormatString = format;
            gv.Columns.Add(c);
        }
        #endregion

        protected void btnExport_Click(object sender, EventArgs e)
        {
            int index = ASPxPageControl1.ActiveTabIndex;
            string sName = "";
            if (index == 0)
            {
                ASPxGridViewExporter1.GridViewID = "gvShuiBiaoXX";
                sName = "水表信息";
                gvShuiBiaoXX.Settings.ShowFooter = false;
                for (int i = 0; i < this.dtShuiBiaoXX.Rows.Count; i++)
                {
                    DataRow row = this.dtShuiBiaoXX.Rows[i];
                    for (int j = 0; j < this.dtShuiBiaoXX.Columns.Count; j++)
                    {
                        if (row[j].GetType().Equals(typeof(string)) && Regex.IsMatch(row[j].ToString(), @"^[+-]?\d*$"))
                        {
                            row[j] = "\r" + row[j];
                        }
                    }
                }
            }
            else if (index == 1)
            {
                ASPxGridViewExporter1.GridViewID = "gvGridTab2";
                sName = "水表全年用水情况";
                gvGridTab2.Settings.ShowFooter = false;
            }
            else if (index == 2)
            {
                ASPxGridViewExporter1.GridViewID = "gvGridTab3";
                sName = "水表月用水情况";
                gvGridTab3.Settings.ShowFooter = false;
            }
            else if (index == 3)
            {
                ASPxGridViewExporter1.GridViewID = "gvGridTab4";
                sName = "水表月用水汇总";
                gvGridTab4.Settings.ShowFooter = false;
            }
            
            ASPxGridViewExporter1.WriteXlsToResponse(sName);

        }

       
    }
}